package com.andyage.admin.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.andyage.admin.bean.MenuBean;
import com.andyage.admin.dao.MenuMapper;
import com.andyage.admin.service.IMenuService;
import com.andyage.util.JsonContent;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Service
public class MenuServiceImpl implements IMenuService {
	@Resource
	private MenuMapper menuMapper;
	@Override
	public String queryMenuDetailsInfo(String roleId) throws Exception {
		List<String> buttonList = menuMapper.queryAllButtonByRoleIdS(roleId);
		List<Integer> intList = new ArrayList<>();
		Map<String, Object> map = new HashMap<>();
		List<MenuBean> list=null;
		if(!buttonList.isEmpty()){
			for (String str : buttonList) {
				if(str!=null && !"".equals(str)){
					String[] buttonId = str.split(",");
					for (int i = 0; i < buttonId.length; i++) {
						intList.add(Integer.valueOf(buttonId[i]));
					}
				}
			}
			if(!intList.isEmpty()){
				map.put("buttonId", intList);
				map.put("roleId", roleId);
				list = menuMapper.queryMenuDetailsInfo(map);
			}else{
				list = menuMapper.queryAllMenu();
			}
		}else{
			list = menuMapper.queryAllMenu();
		}
		return JsonContent.getJsonArray(list, 0);
		/*return JsonContent.getJsonArray(list, 0);*/
	}
	@Override
	public String queryMenuByStaffId(String staffId) throws Exception {
		List<MenuBean> list = menuMapper.queryMenuByStaffId(staffId);
		return JsonContent.getJsonArray(list, 0);
	}

}
